home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
-
-
- Macros for Debugging C Programs
-
- by Bill Rogers
-
- Although symbolic debuggers have reduced the need for use of
- inserting "printf" commands in C programs for debugging, this
- approach still has its use.
-
- The following characteristics would make "printf" commands even
- easier to use:
-
- Conditionally compiled commands,
- Simple commands,
- Easy definition of where the command is located.
-
- Using the "stringizing", "__FILE__" and "__LINE__" features of ANSI
- C, a compact set of debugging macros can be constructed. These
- macros are constructed in the spirit of the ANSI C "assert" macro.
-
- Although these macros can be readily modified, they now assume a
- revision control constant:
-
- const static char RCsid[] = <rcsid string>;
-
- of file scope, and a macro for the function name:
-
- T_FUNC(<func>)
-
- of function scope.
-
- These macros are activated by the compiler command line argument (in
- Lattice C/6.0):
-
- -dTRACE
-
- The forms of the printed line to "stderr" are:
-
- <file>:<line>:<func>:Begin RCsid=
- <rcsid string>
- <file>:<line>:<func>:<type> <var name>=<var value>
- <file>:<line>:<func>:End
-
- The macros are:
-
- T_FUNC(x) Define function name
-
- T_BEGIN() Display function "begin"
- T_END() Display function "end"
-
- T_BOOL(x) Display boolean
- T_CHAR(x) Display character
- T_DBL(x) Display double
-
-
-
-
-
- T_HEX(x) Display unsigned integer in hexadecimal
- T_INT(x) Display integer
- T_FLOAT(x) Display float
- T_LHEX(x) Display unsigned long integer in hexadecimal
- T_LONG(x) Display long
- T_PTR(x) Display pointer as segment:offset
- T_STR(x) Display string
-
- These macros are defined in the header "trace.h" given in Figure 1.
-
- --------------------------------
-
- --------------------------------
- Figure 1. "trace.h"
-
- A demonstration of the use of these macros is given in Figure 2 with
- the output given in Figure 3.
-
- --------------------------------
-
- --------------------------------
- Figure 2. "tracdemo.c"
-
- --------------------------------
-
- --------------------------------
- Figure 3. "tracdemo.lst"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-